package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.bo.EventBo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.EventMapper;
import com.java2207.group1.pojo.Event;
import com.java2207.group1.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("eventService")
public class EventServiceImpl implements EventService {

    @Autowired
    private EventMapper eventMapper;

    @Override
    public LayuiPageVo<Event> eventPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        //mybatis 的分页插件
        PageHelper.startPage(page, limit);

        List<Event> events = eventMapper.selectByParams(params);

        //mybatis 的分页数据结构
        PageInfo<Event> eventPageInfo = new PageInfo<>(events);

        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<Event> eventLayuiPageVo = new LayuiPageVo<>();

        eventLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        eventLayuiPageVo.setMsg("分页列表数据");   // 提示信息
        eventLayuiPageVo.setCount(eventPageInfo.getTotal());     // 总记录数
        eventLayuiPageVo.setData(eventPageInfo.getList());    // 分页的列表数据

        return eventLayuiPageVo;
    }

    @Override
    public int deleteEvent(Integer id) {
        return eventMapper.deleteEvent(id);
    }

    @Override
    public int addEvent(Event event) {
        return eventMapper.addEvent(event);
    }

    @Override
    public int updateEvent(Event event) {
        return eventMapper.updateEvent(event);
    }


    @Override
    public int batchEve(String ids) {
        String[] arr = ids.split(",");
        return eventMapper.batchEve(arr);
    }

    @Override
    public List<EventBo> eventExcelData(Event event) {
        return eventMapper.eventExcelData(event);
    }
}
